home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / decprom / ds5000.md / devDecProm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-31  |  3.3 KB  |  145 lines

  1. /* 
  2.  * devDecProm.c --
  3.  *
  4.  *    Routines that access the Dec PROM device drivers.  This code is
  5.  *    based on DecOS bootstrap code in boot/os/devio.c
  6.  *
  7.  * Copyright 1989 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifdef notdef
  18. static char rcsid[] = "$Header: /sprite/src/boot/decprom/ds3100.md/RCS/devDecProm.c,v 1.1 90/02/16 16:14:07 shirriff Exp $ SPRITE (Berkeley)";
  19. #endif /* not lint */
  20.  
  21.  
  22. #include "sprite.h"
  23. #include "user/fs.h"
  24. #include "kernel/dev.h"
  25. #include "kernel/devFsOpTable.h"
  26. #include "boot.h"
  27. #define _MONFUNCS
  28. #include "kernel/machMon.h"
  29.  
  30. #define DEV_BSIZE 8192
  31.  
  32. #define READ 0
  33. #define WRITE 1
  34.  
  35. #define NO_PRINTF
  36.  
  37. /*
  38.  *----------------------------------------------------------------------
  39.  *
  40.  * DecPromDevOpen --
  41.  *
  42.  *    Open the device used for booting.  This depends on the initialization
  43.  *    of the devicePtr->data field done in Dev_Config.
  44.  *
  45.  * Results:
  46.  *    SUCCESS or FAILURE.
  47.  *
  48.  * Side effects:
  49.  *    None.
  50.  *
  51.  *----------------------------------------------------------------------
  52.  */
  53. ReturnStatus
  54. DecPromDevOpen(devicePtr)
  55.     Fs_Device    *devicePtr;    /* Sprite device description */
  56. {
  57.     int fd;
  58.     char     *boot;
  59.  
  60. #ifndef NO_PRINTF
  61.     Mach_MonPrintf("DecPromDevOpen\n");
  62. #endif
  63.     boot = Mach_MonGetenv("boot");
  64. #ifndef NO_PRINTF
  65.     Mach_MonPrintf("boot = %s\n", boot);
  66. #endif
  67.     fd = Mach_MonOpen(boot,READ);
  68.     if (fd>0) {
  69.     devicePtr->unit = fd;
  70.     return SUCCESS;
  71.     } else {
  72. #ifndef NO_PRINTF
  73.     Mach_MonPrintf("Open failure\n");
  74. #endif
  75.     return FAILURE;
  76.     }
  77. }
  78.  
  79.  
  80. /*
  81.  *----------------------------------------------------------------------
  82.  *
  83.  * DecPromDevRead --
  84.  *
  85.  *    Read from the boot device used for booting.
  86.  *
  87.  * Results:
  88.  *    SUCCESS or FAILURE.
  89.  *
  90.  * Side effects:
  91.  *    The read operation.
  92.  *
  93.  *----------------------------------------------------------------------
  94.  */
  95. ReturnStatus
  96. DecPromDevRead(devicePtr, offset, len, buffer, numBytesPtr)
  97.     Fs_Device    *devicePtr;    /* Sprite device description */
  98.     int offset;            /* Byte offset */
  99.     int len;            /* Byte count;
  100.     char *buffer;        /* Address to read into */
  101.     int *numBytesPtr;        /* Return, the amount actually read */
  102. {
  103.     register int fd = devicePtr->unit;
  104.     register int numBytes;
  105.     register int totalBytes;
  106.     register int toRead;
  107.     int status;
  108.  
  109.     status = Mach_MonLseek(fd, offset, 0);
  110.     if (status<0) {
  111. #ifndef NO_PRINTF
  112.     Mach_MonPrintf("Lseek failure\n");
  113. #endif
  114.     return FAILURE;
  115.     }
  116.  
  117.     /*
  118.      * Break the I/O in to chunks that are edible by the device.
  119.      */
  120.     totalBytes = 0;
  121.     while (len > 0) {
  122.     if (len > DEV_BSIZE) {
  123.         toRead = DEV_BSIZE;
  124.     } else {
  125.         toRead = len;
  126.     }
  127.     numBytes = Mach_MonRead(fd, buffer, toRead);
  128.     if (numBytes <= 0) {
  129.         break;
  130.     }
  131.     buffer += numBytes;
  132.     len -= numBytes;
  133.     totalBytes += numBytes;
  134.     }
  135.     *numBytesPtr = totalBytes;
  136.     if (numBytes <= 0) {
  137. #ifndef NO_PRINTF
  138.     Mach_MonPrintf("Read failure: read(%d, %x, %x)\n",fd,buffer,toRead);
  139. #endif
  140.     return(FAILURE);
  141.     } else {
  142.     return(SUCCESS);
  143.     }
  144. }
  145.